#ifndef FGE_EVENTMANAGER_HPP
#define FGE_EVENTMANAGER_HPP

#include <stdint.h>
#include <vector>
#include <map>

namespace fge
{

struct Event
{
	// I'd really prefer something typesafe instead of this void* nonsense.
	// Something like C#'s custom events would be really nice.
	uint32_t id;
	void *parameters[2];
	int data[4];

	Event(uint32_t id) : id(id) { }
	Event(uint32_t id, void *p1) : id(id) { parameters[0] = p1; }
	Event(uint32_t id, void *p1, void *p2) : id(id) { parameters[0] = p1; parameters[1] = p2; }
};

class IEventReceiver
{
public:
	virtual void ReceiveEvent(const Event &event) = 0;
};

class EventManager
{
public:
	EventManager();
	~EventManager();

	void Register(uint32_t eventId, IEventReceiver*);
	void Unregister(uint32_t eventId, IEventReceiver*);
	void UnregisterAll(IEventReceiver*);

	void AddEvent(const Event &event);
	void ProcessEvents();

private:
	std::vector<Event> events;
	std::vector<Event> eventsToAdd;
	std::map<uint32_t, std::vector<IEventReceiver*> > receivers;
};

}

#endif//FGE_EVENTMANAGER_HPP
